package vn.student.mylib;

import java.util.Date;

public class MyDate {
	static public Date getDate(){
		Date date = new Date();
		return date;
	}
	static public String getRealDate(Date date){
		String str = String.valueOf(date.getDate());
		str = str.length()==2?str:("0"+str);
		return str;
	}
	static public String getRealMonth(Date date){
		String str = String.valueOf(date.getMonth()+1);
		str = str.length()==2?str:("0"+str);
		return str;
	}
	static public String getRealYear(Date date){
		String str = String.valueOf(date.getYear()+1900);
		return str;
	}
	static public Date getDate(String dateStr){
		String[] dateArr = dateStr.split("-");
		Date date = new Date();
		try{
			date.setYear((Integer.valueOf(dateArr[0]))-1900);
			date.setMonth((Integer.valueOf(dateArr[1]))-1);
			date.setDate((Integer.valueOf(dateArr[2])));
		}
		catch(Exception e){
			return null;
		}
		return date;
	}
	static public Date getDate(int yy,int mm, int dd){
		Date date= new Date();
		date.setYear(yy-1900);
		date.setMonth(mm-1);
		date.setDate(dd);
		return date;
	}
	static public String getDateString(Date date){
		String str = "";
		String dateStr = "";
		dateStr += String.valueOf(date.getYear()+1900) + "-";
		str = String.valueOf(date.getMonth()+1);
		dateStr += (str.length()==2?str:("0"+str)) + "-";
		str = String.valueOf(date.getDate());
		dateStr += (str.length()==2?str:("0"+str)); 
		return dateStr;
	}
}
